<template>
    <div>
        <h3>添加</h3>
        <table>
            <tbody>
                <tr>
                    <td>券类型</td>
                    <td>代金券标题</td>
                    <td>图片</td>
                    <td>剩余库存</td>
                    <td>每人限领</td>
                    <td>条件</td>
                    <td>减免金额</td>
                    <td>有限期</td>
                    <td>电话</td>
                </tr>
                <tr v-for="item in brr.a" :key="item.disCountID">
                    <td>{{ item.disCountType }}</td>
                    <td>{{ item.disCountTiTle }}</td>
                    <td><img :src="item.img" width="100" height="100" /></td>
                    <td>{{ item.shengYuNum }}</td>
                    <td>{{ item.xianLingNum }}</td>
                    <td>{{ item.tiaoJian }}</td>
                    <td>{{ item.money }}</td>
                    <td>{{ item.disCountTime }}</td>
                    <td>{{ item.phone }}</td>
                    <td>
                        <input type="button" value="删除" @click="Del(item.disCountID)" class="btn btn-info" />
                        <input type="button" value="修改" @click="Up(item.disCountID)" class="btn btn-info" />
                    </td>
                </tr>
            </tbody>
        </table>
        <div>
            <input type="button" value="首页" @click="fan(1)" class="btn btn-info" />
            <input type="button" value="上一页" @click="fan(arr.PageIndex - 1)" class="btn btn-info" />
            <input type="button" value="下一页" @click="fan(arr.PageIndex + 1)" class="btn btn-info" />
            <input type="button" value="尾页" @click="fan(brr.tatlePage)" class="btn btn-info" />
        </div>
    </div>
</template>

<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRoute, useRouter } from 'vue-router';

let use = useRouter();

let arr: any = reactive({
    PageIndex: 1,
    PageSize: 2
});


let brr: any = reactive({
    "tatlePage": 1,
    "tatleCount": 2,
    "a": []
})

onMounted(() => {
    Show();
})

const Show = () => {
    axios({
        url: "https://localhost:7151/api/DisCount/Show",
        params: arr,
        method: "get"
    })
        .then(res => {
            brr.tatlePage = res.data.tatlePage,
                brr.tatleCount = res.data.tatleCount,
                brr.a = res.data.a
        })
}




const Page = (e: any) => {

    let obj = e.target.files[0];
    let f = new FormData();
    f.append("file", obj);


    axios({
        url: "https://localhost:7151/api/Img/imgs",
        method: "post",
        data: f
    })

        .then(res => {

            arr.img = res.data;


        })
}


const fan = (num: any) => {
    if (num < 1) {
        num = arr.PageIndex
    }
    if (num > brr.tatlePage) {
        num = brr.tatlePage
    }

    arr.PageIndex = num;
    console.log(arr.PageIndex);

    Show();
}
const Del = (id: any) => {
    axios({
        url: "https://localhost:7151/api/DisCount/Del",
        params: { id: id },
        method: "delete"
    })
        .then(res => {
            if (res.data > 0) {
                alert('删除成功');
                Show();
            }
            else {
                alert('删除失败');
            }
        })
}


const Up = (Id: any) => {
    use.push({
        path: "/FanTian",
        query: { id: Id }

    })
}

</script>

<style scoped></style>